#!/bin/sh
# -*- shell-script -*-
# Copyright (C) 2004-2012 GraphicsMagick Group
# Test hald CLUT operations
. ./common.shi
. ${top_srcdir}/utilities/tests/common.sh

# Number of tests we plan to execute
test_plan_fn 12

# Identity for level 12 produces a 1728x1728 pixels image.
# Identity for level 10 produces a 1000x1000 pixels image.
OUTFILE=HaldClutIdentity_out.miff
levels='2 7 8 10 12'
for level in $levels
do
  echo "Testing Hald CLUT identity level ${level} ..."
  identity_image=identity:${level}
  rm -f ${OUTFILE}
  test_command_fn "Hald CLUT identity (level=${level})" ${GM} convert ${CONVERT_FLAGS} ${identity_image} -hald-clut ${identity_image} -label Hald-Clut -compress ${MIFF_COMPRESS} ${OUTFILE}
  test_command_fn "Hald CLUT verify (level=${level})" ${GM} compare -maximum-error 1.5e-11 -metric MAE ${identity_image} -compress ${MIFF_COMPRESS} ${OUTFILE}
  echo
done

XFORM='-negate'
IDENTITY_CLUT='identity:8'
CLUT_OUTPUT=HaldClutTransform_out.miff
REFERENCE_OUTPUT=HaldClutTransformRef_out.miff
XFORM_CLUT=HaldClutTransformCLUT_out.miff

eval ${GM} convert ${IDENTITY_CLUT} ${XFORM} -compress ${MIFF_COMPRESS} ${XFORM_CLUT}
eval ${GM} convert ${MODEL_MIFF} ${XFORM} -compress ${MIFF_COMPRESS} ${REFERENCE_OUTPUT}
test_command_fn 'Hald CLUT emulate negate' ${GM} convert ${MODEL_MIFF} -hald-clut ${XFORM_CLUT} -compress ${MIFF_COMPRESS} ${CLUT_OUTPUT}
test_command_fn 'Hald CLUT verify' ${GM} compare -maximum-error 4.0e-12 -metric MAE ${REFERENCE_OUTPUT} -compress ${MIFF_COMPRESS} ${CLUT_OUTPUT}
:
